<template>
  <div class="admin-layout">
    <div class="admin-sidebar">
      <div class="admin-header">
        <h2><i class="fas fa-cog"></i> 后台管理</h2>
      </div>
      <nav class="admin-nav">
        <router-link to="/admin/users" class="nav-item" active-class="active">
          <i class="fas fa-users"></i>
          用户管理
        </router-link>
        <router-link to="/admin/admins" class="nav-item" active-class="active">
          <i class="fas fa-user-shield"></i>
          管理员管理
        </router-link>
        <router-link to="/admin/products" class="nav-item" active-class="active">
          <i class="fas fa-box"></i>
          商品管理
        </router-link>
        <router-link to="/admin/categories" class="nav-item" active-class="active">
          <i class="fas fa-tags"></i>
          分类管理
        </router-link>
        <router-link to="/admin/orders" class="nav-item" active-class="active">
          <i class="fas fa-shopping-cart"></i>
          订单管理
        </router-link>
        <router-link to="/home" class="nav-item">
          <i class="fas fa-home"></i>
          返回前台
        </router-link>
      </nav>
    </div>
    <div class="admin-content">
      <router-view></router-view>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AdminLayout',
  mounted() {
    // 动态加载Font Awesome
    if (!document.querySelector('link[href*="font-awesome"]')) {
      const link = document.createElement('link');
      link.rel = 'stylesheet';
      link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css';
      document.head.appendChild(link);
    }
  }
}
</script>

<style scoped>
.admin-layout {
  display: flex;
  min-height: 100vh;
  background-color: #f5f5f5;
}

.admin-sidebar {
  width: 250px;
  background-color: #2c3e50;
  color: white;
  box-shadow: 2px 0 5px rgba(0,0,0,0.1);
  position: fixed;
  height: 100vh;
  overflow-y: auto;
}

.admin-header {
  padding: 20px;
  border-bottom: 1px solid #34495e;
  background-color: #34495e;
}

.admin-header h2 {
  margin: 0;
  font-size: 1.5rem;
  color: #ecf0f1;
  display: flex;
  align-items: center;
}

.admin-header h2 i {
  margin-right: 10px;
  color: #3498db;
}

.admin-nav {
  padding: 20px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: 15px 20px;
  color: #bdc3c7;
  text-decoration: none;
  transition: all 0.3s ease;
  border-left: 3px solid transparent;
  font-weight: 500;
}

.nav-item:hover {
  background-color: #34495e;
  color: #ecf0f1;
  border-left-color: #3498db;
  text-decoration: none;
}

.nav-item.active {
  background-color: #34495e;
  color: #3498db;
  border-left-color: #3498db;
}

.nav-item i {
  margin-right: 10px;
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
}

.admin-content {
  flex: 1;
  margin-left: 250px;
  padding: 20px;
  overflow-y: auto;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .admin-sidebar {
    width: 200px;
  }
  
  .admin-content {
    margin-left: 200px;
  }
  
  .admin-header h2 {
    font-size: 1.2rem;
  }
  
  .nav-item {
    padding: 12px 15px;
    font-size: 0.9rem;
  }
}

@media (max-width: 576px) {
  .admin-sidebar {
    width: 100%;
    position: relative;
    height: auto;
  }
  
  .admin-content {
    margin-left: 0;
  }
  
  .admin-layout {
    flex-direction: column;
  }
}
</style>